<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);

//课程报名信息
class manage extends admin{
	
	private $db;
	public $siteid;
	public $admin_id;
	
	function __construct() {
		parent::__construct();
		$this->db = pc_base::load_model('course_sign_model');//加载课程报名信息模型
		$this->course_db = pc_base::load_model('course_nsr_model');//加载课程模型
		$this->talent_db = pc_base::load_model('talent_model');//加载人才库模型
		$this->siteid = get_siteid();//获取站点ID
		$this->admin_id = param::get_cookie('userid');//获取管理员ID
	}
	
	public function init() {
		$condition = "";
		$condition .= "siteid = ".$this->siteid." and status = 1";
		$course_name = $this->course_db->select($condition,'id,name');
		$course_new_name = array();
		foreach ($course_name as $k=>$v){
			$course_new_name[$v['id']] = $v['name'];
		}
		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$where = "";
		$where .= "siteid = ".$this->siteid." and status != 0 and status != 2";
		if (isset($_GET['search'])) {
			$search_key = $_GET['keyword'];
			$course_id = $_GET['course_id'];
			if ($search_key) {
				$where .= " and real_name like '%$search_key%'";
			}
			if ($course_id) {
				$where .= " and course_id = ".$course_id;
			}
		}
		$info = $this->db->listinfo($where,'id DESC',$page,10);
		$pages = $this->db->pages;
		pc_base::load_sys_class('form','',0);
		pc_base::load_sys_class('format','',0);
		$show_header = false;
		include $this->admin_tpl('information_list');
	}
	
	public function detail() {
		$id = isset($_GET['id']) ? intval($_GET['id']) : showmessage(L('message_not_exits'),HTTP_REFERER);
		$info = $this->db->get_one(array('id'=>$id));
		pc_base::load_sys_class('form','',0);
		pc_base::load_sys_class('format','',0);
		include $this->admin_tpl('information_detail');
	}
	
	/**
	 * 课程报名信息导入人才库
	 * @date: 2017年5月10日 下午3:32:11
	 * @author: LIYANG
	 */
	public function handle() {
		$id = isset($_GET['id']) ? intval($_GET['id']) : showmessage(L('message_not_exits'),HTTP_REFERER);
		$info = $this->db->get_one(array('id'=>$id));
		$info['talent_type'] = array('is_student'=>'is_student');
		$result = $this->talent_db->moter_add($info,2);
		if ($result) {
			$information_result = $this->db->update('status = 3',array('id'=>$id));
			if ($information_result) {
				showmessage(L('import_talent_success'),'?m=sign_up&c=manage&a=init');
			} else {
				showmessage(L('import_talent_error'),HTTP_REFERER);
			}
		} else {
			showmessage(L('import_talent_error'),HTTP_REFERER);
		}
	}
}